﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace IGGCore.Parsers
{
    public class BillJamesParser : BaseParser
    {
        private string playersPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + CoreConstants.FILE_PATH_JAMES;

        private XmlNodeList playerList;
        private Random rnd;

        public void LoadPlayer()
        {
            /*
            <player>
            <name>Cy Young</name>
            <pos>P</pos>
            <rank>4</rank>
            <lived>1867 - 1955</lived>
            <note>
            During his 21-year baseball career (1890–1911), he pitched for five different teams. Young established numerous pitching records, some of which have stood for a century. Young compiled 511 wins, which is most in Major League history and 94 ahead of Walter Johnson who is second on the list. Young was elected to the National Baseball Hall of Fame in 1937.
            One year after Young's death, the Cy Young Award was created to honor the previous season's best pitcher. In addition to wins, Young still holds the major league records for most career innings pitched (7,355), most career games started (815), and most complete games (749). He also retired with 316 losses, the most in MLB history.
            </note>
            </player>
             * */

            rnd = new Random();
            XmlDocument playersDoc = new XmlDocument();
            playersDoc.Load(playersPath);
            playerList = playersDoc.GetElementsByTagName("player");
        }

        /// <summary>
        /// Update the history tidbit in the current scoreboard
        /// </summary>
        public Player GetPlayerTidbit()
        {
            Player player = new Player();

            XmlNode nodePlayer = playerList[rnd.Next(playerList.Count)];
            player.NameDisplay = nodePlayer["name"].InnerText;
            player.Position = nodePlayer["pos"].InnerText;
            player.Number = nodePlayer["rank"].InnerText;
            player.Id = nodePlayer["lived"].InnerText;
            player.Report = nodePlayer["note"].InnerText;
            return player;
        }
    }
}
